<template>
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <div class="app-container">
      <!--<el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                     v-hasPermi="['develop:GoodsOrderIn:add']">新增
          </el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>-->

      <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
        :max-height="400">
        <el-table-column label="客户名称" align="center" prop="customerName" width="160">
          <template slot-scope="scope">
            {{scope.row.customerName}}
          </template>
        </el-table-column>
        <!--<el-table-column label="项目名称" align="center" prop="projectId">
          <template slot-scope="scope">
            <dict-tag :options="PrjNameOptions" :value="scope.row.projectId"/>
          </template>
        </el-table-column>-->
        <el-table-column label="供应商名称" align="center" prop="supplierName" />
        <el-table-column label="产品名称" align="center" prop="name" />
        <el-table-column label="产品型号" align="center" prop="model" />
        <!--  <el-table-column label="产品型号明细" align="center" prop="brand"/>-->
        <el-table-column label="计量单位" align="center" prop="unit" />
        <el-table-column label="单价" align="center" prop="costPriceTax" />
        <el-table-column label="数量" align="center" prop="count" />
        <el-table-column label="剩余数量" align="center" prop="remainderCount" />
        <el-table-column label="重量" align="center" prop="dun" />
        <el-table-column label="总价" align="center" prop="costTax" />
        <el-table-column label="剩余价" align="center" prop="shengyu" />
        <!--<el-table-column label="销售人姓名" align="center" prop="saleName"/>-->
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width" width="125">
          <template slot-scope="scope">
            <!-- <el-button size="mini" type="text" icon="el-icon-info"
                       @click="handleView(scope.row)">详情
            </el-button>-->
            <!-- <el-button size="mini" type="text" icon="el-icon-edit"
                       @click="handleUpdate(scope.row)">修改
            </el-button> -->
            <el-popconfirm :title="`确认删除 `+scope.row.id+` 数据项？`" @confirm="handleDelete(scope.row)"
              style="margin-left: 10px;">
              <el-button slot="reference" size="mini" type="text" icon="el-icon-delete">删除
              </el-button>
            </el-popconfirm>
          </template>
        </el-table-column>

      </el-table>

      <GoodsOrderIn-update @ok="getList" ref="goodsOrderInForm"></GoodsOrderIn-update>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </el-dialog>
</template>

<script>
  import {
    deleteAction,
    downloadFile,
    getAction,
    getById
  } from '@/api/manage'
  import GoodsOrderInUpdate from "./GoodsOrderInUpdate";

  export default {
    name: "GoodsOrderInListForm",
    dicts: ['fund_callback', 'sale_type', 'yes_no'],
    components: {
      GoodsOrderInUpdate
    },
    data() {
      return {
        title: "记录",
        open: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        rows: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售信息管理表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          mainId: null,
          name: null,
          brand: null,
          unit: null,
          costPrice: null,
          count: null,
          cost: null,
          validityTerm: null,
          buyId: null,
          buyName: null,
          buyDate: null,
          buyType: null,
          reimburse: null,
          supplierId: null,
          supplierName: null,
          dateRange: "",
          params: {},
        },
        url: {
          list: '/goodsOrderIn/goodsOrderIn/list',
          delete: '/goodsOrderIn/goodsOrderIn/deleted/',
          export: '/goodsOrderIn/goodsOrderIn/export',
        },
        PrjNameOptions: [],
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      // this.intDictsForPrj();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight);
    },
    methods: {
      handleSelectionChange() {

      },
      handleAdd() {
        this.$refs.goodsOrderInForm.addGoodsSale(this.rows);
      },
      handleUpdate(row) {
        this.$refs.goodsOrderInForm.handleUpdate(row);
      },
      handleView(row) {
        this.$refs.goodsOrderInForm.handleUpdate(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        deleteAction(this.url.delete, row.id).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      showrOrderIn(order) {
        this.rows = order;
        let that = this;
        that.queryParams.mainId = order.deptId;
        that.getList();
        that.open = true;
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 查询销售信息管理列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
    }
  };
</script>
